
import React from 'react';
import { Link } from 'react-router-dom';
import { Button,Input,Table,MessageBox} from 'element-react';
import Top  from '../../top/index.js';
import Nav from '../../nav/index.js';
import './view.css';
import axios from 'axios';
import util from '../../../assets/js/util.js';
class View extends React.Component {

    constructor(props) {
        super(props);

        this.state = {

            columns: [

                {
                    label: "回收品类",
                    prop: "date",

                },
                {
                    label: "重量(kg)",
                    prop: "weight",

                }

            ],
            data: [{
                date: '回收品A',
                weight: '20',

            }, {
                date: '回收品B',
                weight: '30',

            }, {
                date: '回收品C',
                weight: '200',

            }],
            checkDta:[{

                num:"",
                type:"",
                factory:"",
                car:"",
                drivernum:"",
                phone:"",
                weight:"",
            }],
            src:[],

        }

    };
    //请求数据
    componentDidMount() {

        //请求登录
        this.gitLogin();
        //分拣中心销售查看
       this.sellerCheck();

    };
    //请求登录
    gitLogin(){
        var params = new URLSearchParams();
        params.append('username','admin');
        params.append('password','98b4dbbed385c3fbbf00d3a69c89d850');

        axios.post('/count/login', params).then((data) => {
            //console.log(data)
        }).catch((e) => {
            console.log(e)
        })
    };

    //分拣中心销售查看
    sellerCheck(){
        let order = this.props.location.pathname.substr(6);
        //console.log(order);
        let params = new URLSearchParams();
        params.append('orderNum',order);
        console.log(params)
        axios.post('/count/sumpackage/selectpackagedetails',params).then((data)=>{
            let res=data.data;
            if(res.code==0){
                //输入框
               let re=res.data.orderTransportList;
               console.log(re);
                let temp = [];
              temp.push({
                  //util.getDateTime(data.ctime)
                  num:re.order_num,type:util.setOrderStatusSeller( re.order_status),factory:re.recycle_factory_name,
                  car:re.carrier_carnum,drivernum:re.order_num,weight:re.net_weight/1000,
              });
              //表格
               let reform=res.data.orderTransportDetaiList;
               console.log(reform.recycleTypeTitle);
               let arr=[];
                reform.forEach ((item, index) => {
                    arr.push({
                        date:item.recycleTypeTitle,weight:item.transportWeight/1000
                    });
                });
                //图片
                let baseImgUrl = res.data.imageList.imageUrl;
                let repic=res.data.imageList.pathList;
               // console.log(repic);
                let picarr=[];
                for(let i=0;i<repic.length;i++){
                    picarr.push(baseImgUrl + repic[i]);
                    console.log(picarr);
                }
                this.setState({
                    checkDta: temp,
                    data:arr,
                    src:picarr
                });


            }else{
                MessageBox.alert(res.msg);
            }
        }).catch((e)=>{
            console.log(e)
        })
    };

    //请求数据
    render() {
        return (
            <div className="main_seller">
                <Top/>
                <Nav seller="active" />
                <div className="con">
                    <div className="top_line">
                        <div className="top_icon">
                            <span className="bg_1"></span>
                        </div>
                        <span className="look demonstration">查看</span>
                        {/*<span type = "info" className="return1">
                            <Link to="/seller">返回</Link>
                        </span>*/}
                    </div>
                    <div className="cont">
                        <div>
                            <span className="left">
                                <Input placeholder={this.state.checkDta[0].num} prepend="订单编号" disabled/>
                            </span>
                            <span className="right">
                                <Input placeholder={this.state.checkDta[0].type} prepend="订单类型 " disabled/>
                            </span>

                        </div>
                        <div>

                            <span className="left">
                                <Input placeholder={this.state.checkDta[0].factory} prepend="目的工厂" disabled/>
                            </span>
                            <span className="right">
                                <Input placeholder={this.state.checkDta[0].weight} prepend="净重(kg)"/>
                            </span>

                        </div>
                        <div>
                            <span className="left">
                                <Input placeholder={this.state.checkDta[0].car} prepend="车辆车牌" disabled/>
                            </span>
                            <span className="right">
                                <Input placeholder={this.state.checkDta[0].drivernum} prepend="司机货运单号" disabled/>
                            </span>

                        </div>


                    </div>
                    <div className="table">
                        <Table
                            style={{width: '100%'}}
                            columns={this.state.columns}
                            data={this.state.data}

                        />
                    </div>
                    <div className="table">
                        {
                            this.state.src.map(
                                function(item,index){
                                    return <img src={item} className="checkimg"/>
                                }.bind(this)
                            )
                        }
                    </div>


                </div>

            </div>
        );
    }
}

export default View
